﻿
Partial Class mp3
    Inherits CPage


#Region "Querystring"
    Public ReadOnly Property ProductId() As Integer
        Get
            If Page.RouteData.Values.ContainsKey("productId") Then
                Return Page.RouteData.Values("productId")
            Else
                Return CWeb.RequestInt("productId")
            End If
        End Get
    End Property
#End Region

#Region "Data"
    Public ReadOnly Property [Product]() As CProduct
        Get
            Return CProduct.Cache.GetById(ProductId)
        End Get
    End Property
#End Region

#Region "Overrides"

    Protected Overrides Sub PageInit()
        If IsNothing(Product) Then
            'Debug info
            For Each i As CProduct In CProduct.Cache.HavingTranscripts
                Dim name As String = i.ProductName.Replace(" ", "_").Replace(":", "").Replace("'", "").Replace("-", "").Replace("""", "").Replace("(", "").Replace(")", "").Replace("/", "").Replace("\", "")
                Response.Write(CConfig.Mp3(i) & "<br/>")
            Next
            'Response.RedirectPermanent(CSitemap.Store)
            Exit Sub
        End If

        'Trivial Check
        If Not Product.Files.HasMp3 Then
            Response.RedirectPermanent(CSitemap.Decide(Product))
            Exit Sub
        End If

        'Basic Function: Redirect to the dropbox file (for smashwords audio links)
        Response.Redirect(CConfig.DropboxUrl(Product.Files.FirstMp3.FileName))

    End Sub
#End Region

End Class
